package com.dyz.leetcode;

public class Rob98 {
    public int rob(int[] nums){
        int n = nums.length;
        if(n==0){return 0;}
        //容器初始化状态
        int[] R = new int[n];
        int[] NR = new int[n];
        R[0] = nums[0];
        NR[0]=0;
        for(int i=1; i<n;i++){
            R[i] = nums[i] + NR[i-1];
            NR[i] = Math.max(NR[i-1],R[i-1]);
        }
        return Math.max(R[n-1], NR[n-1]);
    }
}
